package com.aiolos.hadoop.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;

/**
 * 使用JAVA API操作HDFS文件系统
 *
 * 操作Hadoop的入口：org.apache.hadoop.fs.FileSystem
 *
 * 关键点：
 *        1. 获取Configuration
 *        2. 创建FileSystem
 *        3. 然后就是HDFS API的操作
 */
public class HDFSAPIDemo01 {

    public static void main(String[] args) throws Exception {

        Configuration configuration = new Configuration();

        //1. 获取操作Hadoop的入口：Hadoop的文件系统
        String hadoopMasterUrl = "hdfs://192.168.126.129:8020"; //hadoop主节点的url地址
        String userName = "hadoop";//Hadoop主节点服务器的用户名
        URI uri = new URI(hadoopMasterUrl);
        FileSystem fileSystem = FileSystem.get(uri,configuration,userName);

        //2. 创建文件夹
        Path path = new Path("/hdfsapi/test");
        boolean result = fileSystem.mkdirs(path);
        System.out.println(result);
    }
}
